<?php
    // estilos -- ver por qué no puedo usar class con un css - otra clase debe estar bloqueandolo
    $tabla_orga_td = 'vertical-align: middle; border: none;';    

    // imagenes
    $prev_img = $this->Html->image("restaurante/ic_navegar_left.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_left"));    
    $next_img = $this->Html->image("restaurante/ic_navegar.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_right"));    
    $prev_img_disabled = $this->Html->image("restaurante/ic_nav_left_disabled.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_left_disabled"));    
    $next_img_disabled = $this->Html->image("restaurante/ic_navegar_disabled.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_right_disabled"));    

    $volver_img = $this->Html->image("restaurante/ic_back.png", array("id" => "back_icon"));    
    $nuevo_img = $this->Html->image("restaurante/ic_add.png", array("id" => "add_icon"));    
    $cancel_img = $this->Html->image("restaurante/ic_cancel.png", array("id" => "back_icon"));    
    $save_img = $this->Html->image("restaurante/ic_ok.png", array("id" => "save_icon"));    
    
    $editar_img = $this->Html->image("restaurante/doc_images.png", array("width" => "24px", "height" => "24px"));    
    $elim_img = $this->Html->image("restaurante/delete_small.png", array("width" => "24px", "height" => "24px"));    
    $undo_img = $this->Html->image("restaurante/undo_small.png", array("width" => "24px", "height" => "24px"));    
    
?>

<?php   $desc_estado = array(0 => 'Libre', 1 => 'Abierta', 2 => 'Reservada', 3 => 'Deshabilitada'); 
        $color_estado = array(0 => 'PaleGreen', 1 => '#F78181', 2 => 'SteelBlue', -1 => 'beige', 3 => 'gray'); 
?>

<!--- MARCO DE LA PANTALLA ------>
<table><tr><td style="padding: 20px; background: white; border: none;">

<!--- TITULO --->
<table>
    <tr>
        <td style="width: 15%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->image("restaurante/ic_resto.png", array("width" => "64px", "height" => "64px", "id" => "resto_icon"));?></td>
        <td style="width: 55%; text-align:left; <?php echo $tabla_orga_td;?>"><h1 class="titulo_ventana">MESAS</h1></td>
        <td style="width: 30%; text-align:right; <?php echo $tabla_orga_td;?>">
            <table>
                <tr><td style="text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Usuario: '.$nombre_usuario;?></td></tr>
                <tr><td style="text-align:right; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->link('Cerrar sesión', array("controller"=>"users", "action"=>"logout"), array('title' => 'Cerrar sesión', 'escape' => false));?></td></tr>
            </table>
        </td>
    </tr>      
</table>
<hr>

<?php echo $this->Form->create('Mesas', array('action'=>'/index','novalidate' => true)); ?>
<!--- CONTROLES Y BOTONERA FILTROS ------>
<table>
    <tr>
        <td style="width: 10%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_codigo', array('label' => 'Mesa Nro.')); ?></td>
        <td style="width: 15%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_estado', array('type' => 'checkbox', 'label' => 'Mesas abiertas', 'checked' => true)); ?></td>     
        <td style="width: 15%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_activo', array('checked' => true,'label' => 'Activas')); ?></td>
        <td style="width: 15%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Buscar'; ?></td>
        <td style="width: 15%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Form->submit('restaurante/ic_search.png',array('class' => 'boton-buscar')); ?> </td>
        <td style="width: 15%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Limpiar'; ?></td>
        <td style="width: 15%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Form->button('', array('type'=>'reset','class' => 'boton-limpiar')); ?></td>    
    </tr>        
</table>

<?php echo $this->Form->end(); ?>

<table style="width:100%;">
<tr>
    <td style="width: 45%;">
            <!--- GRILLA ------>
            <table>
                <tr>
                    <th style="width: 20%;"><?php echo $this->Paginator->sort('Mesa.codigo', 'Mesa Nro.', array('direction' => 'asc') ); ?></th>
                    <th style="width: 20%;"><?php echo $this->Paginator->sort('Mesa.estado','Estado',array('direction' => 'asc') ); ?></th>
                    <th style="width: 15%; text-align:center;"><?php echo "Editar"; ?></th>
                    <th style="width: 15%; text-align:center;"><?php echo "Habil./Deshab."; ?></th>
                </tr>
                <?php foreach ($mesas as $mesa): ?>
                <tr>
                    <td style="width: 20%;"><?php echo $mesa['Mesa']['codigo']; ?> </td>
                    <td style="width: 20%;">
                            <?php if($mesa['Mesa']['activo'] == 1) echo $desc_estado[$mesa['Mesa']['estado']]; ?> </td>
            <!--- ICONOS ------>
                    <td style="width: 15%; text-align:center;">
                            <?php 
                            if(($mesa['Mesa']['estado'] != 1) && ($mesa['Mesa']['activo'] == 1)) 
                                echo $this->Html->link($editar_img, '/mesas/editar/'.$mesa['Mesa']['id'], array('escape' => false));
                            ?> 
                    </td>
                    <td style="width: 15%; text-align:center;">
                            <?php if($mesa['Mesa']['activo'] == 0) {
                                echo $this->Html->link($undo_img, '/mesas/habilitar/'.$mesa['Mesa']['id'], array('escape' => false)); 
                            } else {
                                if(($mesa['Mesa']['estado'] == 0) && ($mesa['Mesa']['activo'] == 1))
                                    echo $this->Html->link($elim_img, '/mesas/deshabilitar/'.$mesa['Mesa']['id'], array('escape' => false));
                            }
                            ?> 
                    </td>
                </tr>    
                <?php endforeach; ?>    
            </table>
            <!--- PAGINADO ------>
            <table>
                <tr>
                    <td style="width: 10%; <?php echo $tabla_orga_td;?>"><?php  echo $this->Paginator->prev(!$this->Paginator->hasPrev() ? null : $prev_img, array('escape' => false), !$this->Paginator->hasPrev() ? $prev_img_disabled : null, array('class'=>'prev disabled','escape' => false));?></td>
                    <td style="width: 10%; <?php echo $tabla_orga_td;?>"><?php  echo $this->Paginator->next(!$this->Paginator->hasNext() ? null : $next_img, array('escape' => false), !$this->Paginator->hasNext() ? $next_img_disabled : null, array('class'=>'next disabled','escape' => false));?></td>
                    <td style="width: 80%; <?php echo $tabla_orga_td;?>"></td>
                </tr>
            </table>     
    </td>
    <td style="width: 5%;">
<!--- MESAS UBICACIONES ---> 
    <td style="width: 50%;">
        <table>
        <tr>
            <td style="border: none;width: 80%;">
                <table>
                <?php 
                    $ancho = floor(100.0 / ($max_pos_x + 1));
                    echo '<tr>';
                    echo '<td style="'.$tabla_orga_td.'text-align:center; height: 20px; width: '.$ancho
                            .'%; background-color: transparent;"></td>';
                    for($j = 1; $j <= $max_pos_x; $j++) {
                        echo '<td style="'.$tabla_orga_td.'text-align:center; height: 20px; width: '.$ancho
                            .'%; background-color: transparent;">'.$j.'</td>';                
                    }
                    for($i = 1; $i <= $max_pos_y; $i++) {
                        echo '<tr>';
                        echo '<td style="'.$tabla_orga_td.'text-align:center; height: 20px; width: '.$ancho
                            .'%; background-color: transparent;">'.$i.'</td>';
                        for($j = 1; $j <= $max_pos_x; $j++) {
                            if (isset($m_codigo[$i][$j])) {
                                // hay una mesa asignada en esta ubicación
                                echo '<td style="'.$tabla_orga_td.'text-align:center; height: 20px; width: '.$ancho
                                        .'%; background-color:'.$color_estado[$m_estado[$i][$j]].';">'.$m_codigo[$i][$j].'</td>';
                            } else {
                                // no hay una mesa asignada en esta ubicación
                                echo '<td style="'.$tabla_orga_td.'text-align:center; height: 20px; width: '.$ancho
                                        .'%; background-color:'.$color_estado[-1].';"></td>';
                            }
                        }
                        echo '</tr>';
                    }    
                ?>
                </table>
            </td>
<!--- LEYENDAS ESTADOS --->             
            <td style="border: none;width: 20%;">
                <table>
                <?php    
                    echo '<tr>';
                    echo '<td style="'.$tabla_orga_td.'height:10px;width:15px;background-color:'.$color_estado[0].'";></td>';
                    echo '<td>'.$desc_estado[0].'</td>'; 
                    echo '</tr>';
                    
                    echo '<tr>';
                    echo '<td style="'.$tabla_orga_td.'height:10px;width:15px;background-color:'.$color_estado[1].'";></td>';
                    echo '<td>'.$desc_estado[1].'</td>'; 
                    echo '</tr>';
                    
                    echo '<tr>';
                    echo '<td style="'.$tabla_orga_td.'height:10px;width:15px;background-color:'.$color_estado[2].'";></td>';
                    echo '<td>'.$desc_estado[2].'</td>'; 
                    echo '</tr>';         
 
                    echo '<tr>';
                    echo '<td style="'.$tabla_orga_td.'height:10px;width:15px;background-color:'.$color_estado[3].'";></td>';
                    echo '<td>'.$desc_estado[3].'</td>'; 
                    echo '</tr>';         
 ?>
                </table>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>

<!--- BOTONERA ------->
<table>
    <tr>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Volver'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->link($volver_img, array("controller"=>"mainmenus", "action"=>"index"), array('class' => 'button', 'title' => 'Volver', 'escape' => false));?></td>
        <td style="width: 60%; <?php echo $tabla_orga_td;?>"></td>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Nuevo'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>">
            <?php    echo $this->Html->link($nuevo_img,
                            array('action' => 'nuevo'), 
                            array('class' => 'button', 'title' => 'Nuevo', 'escape' => false,
                                'onclick' => 'Modalbox.show(this.href, {title: this.title, width: 400}); return false;')); 
?>      </td>
    </tr>
</table>

<!--- FIN MARCO DE LA PANTALLA ------>
</td></tr></table>
